Python Programming Fundamentals by Kent D. Lee

Python Programming Fundamentals by Kent D. Lee

Author:Kent D. Lee
Language: eng
Format: epub, pdf
Publisher: Springer London, London


4.3 Mutator Methods

Mutator methods, as the name suggests, change or mutate the state of the object. Sect. 3.​5 introduced the mutability of lists. Mutator methods are called the same as accessor methods. Where an accessor method usually gives you information back, a mutator method may require you to provide some information to the object.

Fig. 4.3Two references to one object

Example 4.5

Here are some calls to mutator methods.

One misconception about object-oriented programming is that assigning one reference to another creates two separate objects. This is not the case as is demonstrated by the following code. This isn’t a problem if the object doesn’t change. However, when the object may be mutated it is important to know that the object is changing and this means that it changes for all references that point at the object.

Example 4.6

Here is an example of one turtle with two different references to it. Both t and r refer the the same turtle.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.